package jmine.tec.web.front.domain;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Comment;
import jmine.tec.persist.annotation.Constraint;
import jmine.tec.persist.annotation.UniqueConstraint;
import jmine.tec.report.impl.table.ReportTableBuilder;
import jmine.tec.web.front.dao.BackOfficeRequestPropertySystemIdentifier;

import org.hibernate.validator.NotNull;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.persist.persister.annotation.NaturalKey;
import bancosys.tec.persist.persister.annotation.SystemId;

/**
 * @author lundberg
 */
@Entity
@Alias("BORQPT")
@Table(name = "BACK_OFFICE_REQUEST_PROPERTY")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Constraint(suffix = "JT_0")
@DiscriminatorColumn(name = "TP", discriminatorType = DiscriminatorType.INTEGER)
@Comment(table = "BACK_OFFICE_REQUEST_PROPERTY", column = "TP", value = "TIPO DA PROPRIEDADE.")
@Documentation("PROPRIEDADE DE REQUISICOES DE BACK OFFICE.")
@SequenceGenerator(name = "SEQ_BORQPT", sequenceName = "SEQ_BORQPT")
public abstract class BackOfficeRequestProperty extends PersistableBusinessObject {

    private Long id;

    private String mnemonic;

    private String description;

    /**
     * @return the id
     */
    @Id
    @SystemId
    @GeneratedValue(generator = "SEQ_BORQPT")
    @Column(name = "COD_BACK_OFFICE_REQ_PROP", nullable = false)
    @Documentation("CODIGO DA PROPRIEDADE DE REQUISICOES DE BACK OFFICE.")
    public Long getId() {
        return this.id;
    }

    /**
     * @return the mnemonic
     */
    @NotNull
    @NaturalKey
    @UniqueConstraint(suffix = "JT_0")
    @Column(name = "MNE", nullable = false)
    @Documentation("MNEMONICO DA PROPRIEDADE.")
    public String getMnemonic() {
        return this.mnemonic;
    }

    /**
     * @return the description
     */
    @NotNull
    @Column(name = "DESCR", nullable = false)
    @Documentation("DESCRICAO DA PROPRIEDADE.")
    public String getDescription() {
        return this.description;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param mnemonic the mnemonic to set
     */
    public void setMnemonic(String mnemonic) {
        this.mnemonic = mnemonic;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Checks is this property corresponds to the given identifier
     * 
     * @param identifier identifier
     * @return boolean
     */
    public boolean isIdentifiedBy(BackOfficeRequestPropertySystemIdentifier identifier) {
        return identifier.getSystemId().equals(this.getId());
    }

    /**
     * Sets up a report column that displays informations about this property
     * 
     * @param builder builder
     */
    public abstract void setUpReportColumn(ReportTableBuilder<BackOfficeRequest> builder);
}
